/**
* @description: 剑指 Offer 56 - II. 数组中数字出现的次数 II
* @author hewei
* @date 2022/7/22 21:25
* @version 1.0
*/

public class SingleNumber2 {

    public int singleNumber(int[] nums) {
        int[] temp = new int[32];
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < 32; j++) {
                temp[j] += nums[i] >> j & 1;
            }
        }
        int ans = 0;
        for (int i = 0; i < temp.length; i++) {
            ans += (1 << i) * (temp[i] % 3);
        }
        return ans;
    }
}
